package com.bdcom.autotest.ui.snp;

import com.bdcom.autotest.interaction.bean.Netcard;
import com.bdcom.autotest.interaction.http.NetcardUtil;
import com.bdcom.autotest.interaction.step.StepThread;
import com.bdcom.autotest.util.Prop;
import com.bdcom.autotest.util.UIUtil;
import sun.nio.ch.Net;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class PanelForSelectNetCard extends AbsPanel {
	public PanelForSelectNetCard() {
		this.setBackground(Color.WHITE);
		this.setPreferredSize(new Dimension( 0 , 250 ));
		JPanel p1 = UIUtil.createPanel();
		JLabel label1=new JLabel("选择网卡：");    //创建标签
		JComboBox cmb=new JComboBox();    //创建JComboBox
		List<Netcard>  netcards = NetcardUtil.getAllNetcards();
		for(Netcard netcard:netcards){
			cmb.addItem(netcard.getCardName());
		}
		Netcard currentNetcard = NetcardUtil.getSelectedNetcard();
		cmb.setSelectedItem(currentNetcard.getCardName());
		p1.add(label1);
		p1.add(cmb);
		JPanel p2 = UIUtil.createPanel();
		JButton btn = new JButton("确定");
		btn.addActionListener( new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				btn.setEnabled(false);
				for(Netcard netcard:netcards){
					String selectItem = (String)cmb.getSelectedItem();
					if(selectItem.equals(netcard.getCardName())){
						NetcardUtil.setSelectedNetcard(netcard);
						break;
					}
				}
				JOptionPane.showMessageDialog(null, "选择成功！");
				btn.setEnabled(true);
			}
		});
		p2.add(btn);
		this.add(p1);
		this.add(p2);
	}
	
}
